﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using System.IO;
using Bitis_KeToanThue_Pro_DungChung.Common;
using Bitis_KeToanThue_Pro_QuanTri.AccessDatabase;
using Telerik.WinControls.Data;
using System.Reflection;

namespace Bitis_KeToanThue_Pro_QuanTri.Form
{
    public partial class frmPhanNhomMenu : Telerik.WinControls.UI.RadForm
    {
        PhanNhomMenu pn = new PhanNhomMenu();
        public static string option = "";
        public static int ID = 0;
        
        public frmPhanNhomMenu()
        {
            InitializeComponent();
            txtMenu.Enabled = false;
            khoitaogrid();
            //
            ClassXuLyChung.loadcombodungchung(cbCommand, pn.loadcombocommand(), "CommandName", "IDCN");
            this.muticolumparent.AutoSizeDropDownToBestFit = false;
            this.muticolumparent.AutoFilter = true;

            RadMultiColumnComboBoxElement multiColumnComboElement3 = this.muticolumparent.MultiColumnComboBoxElement;
            multiColumnComboElement3.DropDownSizingMode = SizingMode.UpDownAndRightBottom;
            multiColumnComboElement3.DropDownMinSize = new Size(900, 350);
            //  multiColumnComboElement3.AutoSize = true;
            multiColumnComboElement3.EditorControl.MasterTemplate.AutoGenerateColumns = false;
            multiColumnComboElement3.EditorControl.MasterTemplate.AllowAutoSizeColumns = true;
            GridViewTextBoxColumn column201 = new GridViewTextBoxColumn("MenuID") { HeaderText = "ID", Width = 50, TextAlignment = ContentAlignment.MiddleCenter };
            multiColumnComboElement3.Columns.Add(column201);

            GridViewTextBoxColumn column211 = new GridViewTextBoxColumn("TenMenu")
            {
                HeaderText = "Tên Menu", 
                 Width = 200,
                TextAlignment = ContentAlignment.MiddleCenter 
            };
            multiColumnComboElement3.Columns.Add(column211);
            GridViewTextBoxColumn column222 = new GridViewTextBoxColumn("TenModule") { HeaderText = "Module", Width = 200, TextAlignment = ContentAlignment.MiddleCenter };
            multiColumnComboElement3.Columns.Add(column222);
            GridViewTextBoxColumn column223 = new GridViewTextBoxColumn("TenThuMuc") { HeaderText = "Thư Mục", Width = 100, TextAlignment = ContentAlignment.MiddleCenter };
            multiColumnComboElement3.Columns.Add(column223);

            GridViewTextBoxColumn column225 = new GridViewTextBoxColumn("TenForm") { HeaderText = "Tên Form", Width = 200, TextAlignment = ContentAlignment.MiddleCenter };
            multiColumnComboElement3.Columns.Add(column225);
            GridViewTextBoxColumn column224 = new GridViewTextBoxColumn("CapMenu") { HeaderText = "Lever", Width = 120, TextAlignment = ContentAlignment.MiddleCenter };
            multiColumnComboElement3.Columns.Add(column224);
            //
            //

            this.multicolummenucon.AutoSizeDropDownToBestFit = false;
            this.multicolummenucon.AutoFilter = true;

            RadMultiColumnComboBoxElement multiColumnComboElement4 = this.multicolummenucon.MultiColumnComboBoxElement;
            multiColumnComboElement4.DropDownSizingMode = SizingMode.UpDownAndRightBottom;
            multiColumnComboElement4.DropDownMinSize = new Size(790, 350);
            //  multiColumnComboElement3.AutoSize = true;
            multiColumnComboElement4.EditorControl.MasterTemplate.AutoGenerateColumns = false;
            multiColumnComboElement4.EditorControl.MasterTemplate.AllowAutoSizeColumns = true;
            GridViewTextBoxColumn column2010 = new GridViewTextBoxColumn("MenuID") { HeaderText = "ID", Width = 50, TextAlignment = ContentAlignment.MiddleCenter };
            multiColumnComboElement4.Columns.Add(column2010);

            GridViewTextBoxColumn column2111 = new GridViewTextBoxColumn("TenMenu")
            {
                HeaderText = "Tên Menu",
                Width = 200,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            multiColumnComboElement4.Columns.Add(column2111);
            GridViewTextBoxColumn column2222 = new GridViewTextBoxColumn("TenModule") { HeaderText = "Module", Width = 200, TextAlignment = ContentAlignment.MiddleCenter };
            multiColumnComboElement4.Columns.Add(column2222);
            GridViewTextBoxColumn column2230 = new GridViewTextBoxColumn("TenThuMuc") { HeaderText = "Thư Mục", Width = 100, TextAlignment = ContentAlignment.MiddleCenter };
            multiColumnComboElement4.Columns.Add(column2230);

            GridViewTextBoxColumn column2250 = new GridViewTextBoxColumn("TenForm") { HeaderText = "Tên Form", Width = 200, TextAlignment = ContentAlignment.MiddleCenter };
            multiColumnComboElement4.Columns.Add(column2250);
         
            //
            
            ClassXuLyChung.loadcombodungchung(cbNhomMenu, pn.loadcombonhom(), "TenNhomMenuND", "MaNhomMenuND");

            sudung2buttonupdatedata(false);
            sudung2buttonaction(true);
            sudung1buttonaction(true);
            sudungcontrol(false);
            if (BienHeThong.ht_quyencapnhat == 1)
            {
                btnSua.Enabled = true;
                btnThem.Enabled = true;
                btnCapNhatQuyen.Enabled = true;
                btnEditTree.Enabled = true;
            }
            else
            {
                btnSua.Enabled = false;
                btnThem.Enabled = false;
                btnCapNhatQuyen.Enabled = false;
                btnEditTree.Enabled = false;
            }
            if (BienHeThong.ht_quyenxoa == 1)
            {
                btnXoa.Enabled = true;
            }
            else
            {
                btnXoa.Enabled = false;
            }
        }
        public void sudungcontrol(bool trangthai)
        {
            if (option == "Sua")
            {
                cbCap.Enabled = false;
                multicolummenucon.Enabled = false;
            }
            else
            {
                cbCap.Enabled = trangthai;
                multicolummenucon.Enabled = trangthai;
            }
            muticolumparent.Enabled = trangthai;
            cbCommand.Enabled = trangthai;
        }
        public void sudung2buttonupdatedata(bool trangthai)
        {
           btnKhong.Enabled= trangthai;
           btnLuu.Enabled = trangthai;
         
        }
        public void sudung2buttonaction(bool trangthai)
        {
            btnThem.Enabled= trangthai;

            btnSua.Enabled= trangthai;
        }
        public void sudung1buttonaction(bool trangthai)
        {
            btnXoa.Enabled= trangthai;
        }
        public void loadmulticolumnmenuparent(int manhom,int menucap)
        {
            DataTable dt = new DataTable();
            dt = pn.loadmultimenuparent(manhom,menucap);
            this.muticolumparent.DataSource = dt;
            muticolumparent.DisplayMember = "TenMenu";
            muticolumparent.ValueMember = "MenuID";
            FilterDescriptor descriptor = new FilterDescriptor(this.muticolumparent.DisplayMember, FilterOperator.StartsWith, string.Empty);
            this.muticolumparent.EditorControl.FilterDescriptors.Add(descriptor);
            this.muticolumparent.DropDownStyle = RadDropDownStyle.DropDown;
        }
        public void loadmulticolumnmenucon(int manhom)
        {
            DataTable dt = new DataTable();
            dt = pn.loadcombomenucon(manhom);
            this.multicolummenucon.DataSource = dt;
            multicolummenucon.DisplayMember = "TenMenu";
            multicolummenucon.ValueMember = "MenuID";
            FilterDescriptor descriptor = new FilterDescriptor(this.multicolummenucon.DisplayMember, FilterOperator.StartsWith, string.Empty);
            this.multicolummenucon.EditorControl.FilterDescriptors.Add(descriptor);
            this.multicolummenucon.DropDownStyle = RadDropDownStyle.DropDown;
        }
        private void loadgrid(int manhom)
        {
            this.radGridView1.DataSource = pn.loadluoi(manhom);
        }
        private void UpdatePanelInfo(GridViewRowInfo currentRow)
        {
            if (currentRow != null && !(currentRow is GridViewNewRowInfo))
            {
                ID = ClassXuLyChung.GetSafeInt(currentRow.Cells[1].Value);
                cbCommand.SelectedValue = ClassXuLyChung.GetSafeInt(currentRow.Cells[10].Value);
                cbCap.SelectedValue = ClassXuLyChung.GetSafeInt(currentRow.Cells[9].Value);
                muticolumparent.SelectedValue = ClassXuLyChung.GetSafeInt(currentRow.Cells[8].Value);
                multicolummenucon.SelectedValue = ClassXuLyChung.GetSafeInt(currentRow.Cells[2].Value);
                txtMenu.Text = ClassXuLyChung.GetSafeString(currentRow.Cells[3].Value);
                
            }
            else
            {
                ID = 0;


            }
        }
        private void khoitaogrid()
        {
            this.radGridView1.EnableHotTracking = true;
            this.radGridView1.ShowFilteringRow = false;
            this.radGridView1.EnableFiltering = true;
            this.radGridView1.MasterTemplate.ShowHeaderCellButtons = true;
            this.radGridView1.MasterTemplate.ShowFilteringRow = false;
            this.radGridView1.MasterTemplate.AutoExpandGroups = true;
            this.radGridView1.TableElement.RowHeight = 32;
            this.radGridView1.MasterTemplate.AllowAddNewRow = false;
            this.radGridView1.MasterTemplate.AutoGenerateColumns = false;
            this.radGridView1.MasterTemplate.AllowEditRow = true;
            this.radGridView1.MasterTemplate.AllowDeleteRow = false;
            this.radGridView1.MasterTemplate.EnableSorting = true;
            this.radGridView1.MasterTemplate.AllowAutoSizeColumns = true;
            this.radGridView1.AutoScroll = true;
            this.radGridView1.EnableAlternatingRowColor = true;

            CustomCheckBoxColumn checkBoxColumn = new CustomCheckBoxColumn()
            {
                HeaderText = "",
           //     FieldName = "Chon",
                Name = "Chon",
                Width = 25,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(checkBoxColumn);

            GridViewTextBoxColumn textBoxColumn7 = new GridViewTextBoxColumn()
            {
                FieldName = "ID",
                Name = "ID",
                HeaderText = "ID",
                Width = 107,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn7);

            GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn()
            {
                FieldName = "MenuID",
                Name = "MenuID",
                HeaderText = "ID",
                Width = 40,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn);

            GridViewTextBoxColumn textBoxColumn1 = new GridViewTextBoxColumn()
            {
                FieldName = "TenMenu",
                Name = "TenMenu",
                HeaderText = "Tên Menu",
                Width = 200,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn1);

           

            GridViewTextBoxColumn textBoxColumn3 = new GridViewTextBoxColumn()
            {
                FieldName = "TenModule",
                Name = "TenModule",
                HeaderText = "Module",
                Width = 190,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn3);

            GridViewTextBoxColumn textBoxColumn4 = new GridViewTextBoxColumn()
            {
                FieldName = "TenThuMuc",
                Name = "TenThuMuc",
                HeaderText = "Thư Mục",
                Width = 90,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn4);

            GridViewTextBoxColumn textBoxColumn5 = new GridViewTextBoxColumn()
            {
                FieldName = "TenForm",
                Name = "TenForm",
                HeaderText = "Tên Form",
                Width = 200,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn5);



            GridViewImageColumn imagecolumn = new GridViewImageColumn()
            {
                FieldName = "Hinh",
                Name = "Hinh",
                HeaderText = "Icon",
                Width = 32,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter,
                ImageLayout = ImageLayout.Stretch,
                ImageAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(imagecolumn);

            GridViewTextBoxColumn textBoxColumn9 = new GridViewTextBoxColumn()
            {
                FieldName = "MenuCha",
                Name = "MenuCha",
                HeaderText = "Menu Cha",
                Width = 70,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn9);

            GridViewTextBoxColumn textBoxColumn10 = new GridViewTextBoxColumn()
            {
                FieldName = "Cap",
                Name = "Cap",
                HeaderText = "Cấp",
                Width = 40,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn10);

            GridViewTextBoxColumn textBoxColumn19 = new GridViewTextBoxColumn()
            {
                FieldName = "IDCN",
                Name = "IDCN",
                HeaderText = "IDCN",
                Width = 50,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn19);

            GridViewTextBoxColumn textBoxColumn22 = new GridViewTextBoxColumn()
            {
                FieldName = "CommandName",
                Name = "CommandName",
                HeaderText = "Command Name",
                Width = 150,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn22);

            CustomCheckBoxColumn checkBoxColumn1 = new CustomCheckBoxColumn()
            {
                HeaderText = "",
                FieldName = "Quyen_CapNhat",
                Name = "Quyen_CapNhat",
                Width = 60,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(checkBoxColumn1);


            CustomCheckBoxColumn checkBoxColumn2 = new CustomCheckBoxColumn()
            {
                HeaderText = "",
                FieldName = "Quyen_Xem",
                Name = "Quyen_Xem",
                Width = 60,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(checkBoxColumn2);

            CustomCheckBoxColumn checkBoxColumn3 = new CustomCheckBoxColumn()
            {
                HeaderText = "",
                FieldName = "Quyen_Xoa",
                Name = "Quyen_Xoa",
                Width = 60,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(checkBoxColumn3);

            GridViewCommandColumn CommandColumn = new GridViewCommandColumn()
            {
                HeaderText = "Sửa",
                Name = "Sua",
                Width = 40,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter,

                Image = Image.FromFile(Application.StartupPath + @"\\Images\\sua.png")
            };
            this.radGridView1.Columns.Add(CommandColumn);

            ColumnGroupsViewDefinition def = new ColumnGroupsViewDefinition();

            def.ColumnGroups.Add(new GridViewColumnGroup("Đơn Vị Kiểm Tra"));
            def.ColumnGroups[0].ShowHeader = false;
            def.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[0]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[1]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[2]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[3]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[4]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[5]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[6]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[7]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[8]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[9]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[10]);
            def.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns[11]);

            def.ColumnGroups.Add(new GridViewColumnGroup("Cập Nhật"));
            def.ColumnGroups[1].ShowHeader = true;
            def.ColumnGroups[1].Rows.Add(new GridViewColumnGroupRow());
            def.ColumnGroups[1].Rows[0].Columns.Add(this.radGridView1.Columns[12]);

            def.ColumnGroups.Add(new GridViewColumnGroup("Xem"));
            def.ColumnGroups[2].ShowHeader = true;
            def.ColumnGroups[2].Rows.Add(new GridViewColumnGroupRow());
            def.ColumnGroups[2].Rows[0].Columns.Add(this.radGridView1.Columns[13]);

            def.ColumnGroups.Add(new GridViewColumnGroup("Xóa"));
            def.ColumnGroups[3].ShowHeader = true;
            def.ColumnGroups[3].Rows.Add(new GridViewColumnGroupRow());
            def.ColumnGroups[3].Rows[0].Columns.Add(this.radGridView1.Columns[14]);
            this.radGridView1.ViewDefinition = def;

            def.ColumnGroups.Add(new GridViewColumnGroup("Sửa"));
            def.ColumnGroups[4].ShowHeader = false;
            def.ColumnGroups[4].Rows.Add(new GridViewColumnGroupRow());
            def.ColumnGroups[4].Rows[0].Columns.Add(this.radGridView1.Columns[15]);
            this.radGridView1.ViewDefinition = def;
        }

        private void cbNhomMenu_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            if (cbNhomMenu.SelectedIndex >= 0)
            {

                loadgrid(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));
                ClassXuLyChung.loadcombodungchung(cbCap, pn.loadcombolever(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue)), "LeverName", "Lever");
                loadmulticolumnmenuparent(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue), ClassXuLyChung.GetSafeInt(cbCap.SelectedValue));
                loadmulticolumnmenucon(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));
                UpdatePanelInfo(this.radGridView1.CurrentRow);
            }
        }
     
        private void txtTimKiem_TextChanged(object sender, EventArgs e)
        {
            ClassXuLyChung.tuychontimkiemtrenluoi(txtTimKiem, radGridView1, 2, 3);
        }

        private void cbCap_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            if (cbCap.SelectedIndex >= 0)
            {
                loadmulticolumnmenuparent(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue), ClassXuLyChung.GetSafeInt(cbCap.SelectedValue));
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            option = "Them";
            sudungcontrol(true);
            sudung2buttonaction(false);
            sudung1buttonaction(false);
            sudung2buttonupdatedata(true);
            trangthaisudungluoi(false);
        }
        private void trangthaisudungluoi(bool trangthaidung)
        {
            radGridView1.Enabled = trangthaidung;
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            option = "Sua";
            trangthaisudungluoi(true);
            sudungcontrol(true);
            sudung2buttonaction(false);
            sudung1buttonaction(false);
            sudung2buttonupdatedata(true);
        }

        private void btnKhong_Click(object sender, EventArgs e)
        {
            option = "";
            sudungcontrol(false);
            trangthaisudungluoi(true);
            sudung2buttonaction(true);
            sudung1buttonaction(true);
            sudung2buttonupdatedata(false);
            loadgrid(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));
            UpdatePanelInfo(this.radGridView1.CurrentRow);
        }

        private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
        {
            try
            {

                if (radGridView1.CurrentRow.Cells[15].IsCurrent == true)
                {

                    UpdatePanelInfo(this.radGridView1.CurrentRow);




                }

            }
            catch
            {
                return;
            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {

            if (option == "Them")
            {
                if (pn.them(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue), ClassXuLyChung.GetSafeInt(multicolummenucon.SelectedValue), ClassXuLyChung.GetSafeInt(cbCap.SelectedValue), ClassXuLyChung.GetSafeInt(muticolumparent.SelectedValue), ClassXuLyChung.GetSafeInt(cbCommand.SelectedValue)) == 1)
                {
                    RadMessageBox.Show(String.Format("Thêm Thành Công Menu \n : {0} Vào Nhóm {1}", ClassXuLyChung.GetSafeString(multicolummenucon.Text), ClassXuLyChung.GetSafeString(cbNhomMenu.Text)), "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Info);
                }
                else
                {
                    RadMessageBox.Show(String.Format("Menu : {0} đã tồn tại \n trong nhóm {1}", ClassXuLyChung.GetSafeString(multicolummenucon.Text), ClassXuLyChung.GetSafeString(cbNhomMenu.Text)), "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
                }
            }
            else
            {
                if (option == "Sua")
                {
                    if (ID != 0)
                    {
                        if (pn.sua(ID, ClassXuLyChung.GetSafeInt(muticolumparent.SelectedValue), ClassXuLyChung.GetSafeInt(cbCommand.SelectedValue)) == 1)
                        {
                            RadMessageBox.Show(String.Format("Cập Nhật Thành Công Menu \n : {0} Vào Nhóm {1}", ClassXuLyChung.GetSafeString(txtMenu.Text), ClassXuLyChung.GetSafeString(cbNhomMenu.Text)), "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Info);
                        }
                        else
                        {
                            RadMessageBox.Show("Menu này không tồn tại", "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
                        }
                    }
                    else
                    {
                        RadMessageBox.Show("Không tồn tại dữ liệu ", "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
                    }
                }
            }
            option = "";
            
            ClassXuLyChung.loadcombodungchung(cbCap, pn.loadcombolever(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue)), "LeverName", "Lever");
         //   loadmulticolumnmenuparent(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue), ClassXuLyChung.GetSafeInt(cbCap.SelectedValue));
            loadmulticolumnmenucon(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));
            sudungcontrol(false);
            sudung2buttonaction(true);
            sudung1buttonaction(true);
            sudung2buttonupdatedata(false);
            trangthaisudungluoi(true);

            loadgrid(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));
            UpdatePanelInfo(this.radGridView1.CurrentRow);
        }

        private void multicolummenucon_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (multicolummenucon.SelectedIndex >= 0)
            {
                txtMenu.Text = ClassXuLyChung.GetSafeString(multicolummenucon.Text);
            }
        }


        private void btnCapNhatQuyen_Click(object sender, EventArgs e)
        {
            int checkdk = 0;

            DataTable dtChanges = new DataTable();
            DataTable dt = (DataTable)radGridView1.DataSource;
            dtChanges = dt.GetChanges(DataRowState.Modified);
         
            // dtChanges = dt.GetChanges();
           
            if (dtChanges != null)
            {
                for (int i = 0; i < dtChanges.Rows.Count; i++)
                {

                    int capnhat_u = ClassXuLyChung.GetSafeBoolInt(dtChanges.Rows[i]["Quyen_CapNhat"]);
                    int xem_u = ClassXuLyChung.GetSafeBoolInt(dtChanges.Rows[i]["Quyen_Xem"]);
                   int xoa_u = ClassXuLyChung.GetSafeBoolInt(dtChanges.Rows[i]["Quyen_Xoa"]);

                   int idupdate = ClassXuLyChung.GetSafeInt(dtChanges.Rows[i]["ID"]);


                    try
                    {
                        pn.capnhatquyen(idupdate,capnhat_u,xem_u,xoa_u);


                    }
                    catch (Exception ex)
                    {
                        RadMessageBox.Show("Lỗi :" + ex.ToString(), "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Error);
                        checkdk = 1;
                    }

                }
                if (checkdk == 0)
                {
                    RadMessageBox.Show("Cập Nhật Thành Công", "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Info);
                }
                checkdk = 0;
                dtChanges = null;
            }


            loadgrid(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));
            UpdatePanelInfo(this.radGridView1.CurrentRow);

          
           
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            

            int checkdk = 0;
            DialogResult kq = RadMessageBox.Show("Bạn có muốn chắc xóa các dòng  được chọn không ???", "Thông Báo", MessageBoxButtons.YesNo, RadMessageIcon.Question);
            if (kq == DialogResult.Yes)
            {
                for (int i = 0; i < radGridView1.Rows.Count; i++)
                {
                    if (radGridView1.Rows[i].Cells[0].Value != null)
                    {
                        bool isChecked = (bool)radGridView1.Rows[i].Cells[0].Value;
                        if (isChecked == true)
                        {
                            checkdk = 1;
                            pn.xoa(ClassXuLyChung.GetSafeInt(radGridView1.Rows[i].Cells[1].Value));

                        }
                    }
                }

                if (checkdk == 1)
                {
                    RadMessageBox.Show("Xóa Thành Công", "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Info);
                }
                else
                {
                    RadMessageBox.Show("Bạn chưa chọn dòng để xóa", "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
                }

            }

            ClassXuLyChung.loadcombodungchung(cbCap, pn.loadcombolever(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue)), "LeverName", "Lever");
            //   loadmulticolumnmenuparent(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue), ClassXuLyChung.GetSafeInt(cbCap.SelectedValue));
            loadmulticolumnmenucon(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));

            loadgrid(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));
            UpdatePanelInfo(this.radGridView1.CurrentRow);
             
        }

        private void btnXemMenu_Click(object sender, EventArgs e)
        {
            frmViewMenu frm = new frmViewMenu(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));
            frm.ShowDialog();
        }

        private void btnEditTree_Click(object sender, EventArgs e)
        {
            frmEditTree frm = new frmEditTree(ClassXuLyChung.GetSafeInt(cbNhomMenu.SelectedValue));
            frm.ShowDialog();
        }
    }
}
